package com.ys.controller.web.business;

import com.ys.config.MenuId;
import com.ys.entity.business.ThrOperateCompanyEuropeTrade;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 运营公司表欧洲贸易合规
 */
@Controller
@RequestMapping("/web/business/thrOperateCompanyEuropeTrade")
public class WebThrOperateCompanyEuropeTradeController {
	private static final Logger logger = LoggerFactory.getLogger(WebThrOperateCompanyEuropeTradeController.class);

	@Autowired
	private CommonApiService<ThrOperateCompanyEuropeTrade> commonApiService;

    /*
     * 新增
     */
    @GetMapping("/toAdd")
    public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response) {
        try {
            model.addAttribute("onProcess", 0);
            return  commonApiService.toAdd(model, new ThrOperateCompanyEuropeTrade(), MenuId.THR_OperateCompanyEuropeTrade, null, null);
        }catch (Exception e) {
            logger.error("新增页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }

    /*
     * 编辑
     */
    @GetMapping("/toEdit")
    public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response, Long id) {
        try {
            Map<String,Object> entity = new  ThrOperateCompanyEuropeTrade()
                    .addLeftJoin("THR_OperateCompanyApply O ON O.Vgsbm = A.Vgsbm")
                    .addField("O.Vgsjc AS vgsjc")

                    .addLeftJoin("TB_Country C ON C.Code = A.CountryCode")
                    .addField("C.Name AS countryName")

                    .addLeftJoin("TB_Country C2 ON C2.Code = A.EoriCountryCode")
                    .addField("C2.Name AS eoriCountryName")
                    .setId(id).queryFirstMap();
            Map<String, Object> extraParam = new HashMap<>();
            //关联数据
            extraParam.put("vgsjc", entity.get("vgsjc"));
            extraParam.put("countryName", entity.get("countryName"));
            extraParam.put("eoriCountryName", entity.get("eoriCountryName"));
            model.addAttribute("onProcess", 0);
            return commonApiService.toEdit(model,id, new ThrOperateCompanyEuropeTrade(), MenuId.THR_OperateCompanyEuropeTrade, extraParam, null);
        }catch (Exception e) {
            logger.error("编辑页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }


    /*
     * 详情
     */
    @GetMapping("/toDetail")
    public String toDetail(Model model, HttpServletRequest request, HttpServletResponse response, Long id) {
        try {
            Map<String,Object> entity = new  ThrOperateCompanyEuropeTrade()
                    .addLeftJoin("THR_OperateCompanyApply O ON O.Vgsbm = A.Vgsbm")
                    .addField("O.Vgsjc AS vgsjc")

                    .addLeftJoin("TB_Country C ON C.Code = A.CountryCode")
                    .addField("C.Name AS countryName")

                    .addLeftJoin("TB_Country C2 ON C2.Code = A.EoriCountryCode")
                    .addField("C2.Name AS eoriCountryName")
                    .setId(id).queryFirstMap();
            Map<String, Object> extraParam = new HashMap<>();
            //关联数据
            extraParam.put("vgsjc", entity.get("vgsjc"));
            extraParam.put("countryName", entity.get("countryName"));
            extraParam.put("eoriCountryName", entity.get("eoriCountryName"));
            model.addAttribute("onProcess", 1);
            return commonApiService.toDetail(model,id, new ThrOperateCompanyEuropeTrade(), MenuId.THR_OperateCompanyEuropeTrade, extraParam, null);
        }catch (Exception e) {
            logger.error("详情页面出错：",e.getMessage(),e);
            return W.error(model, e.getMessage());
        }
    }




}






